'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const ctx = this.ctx;
    const { page, limit } = ctx.query;
    // const user = await ctx.service.user.users(page, limit);
    let user = await ctx.service.user.users(page, limit);
    user = user.map(item => {
      if(item.user_tag) {
        item.user_tag = item.user_tag.split('%-%');
      }
      return item;
    })
    ctx.body = {
        code: 1,
        data: user,
        msg: 'ok'
    };

  }

  async test() {
    this.ctx.body = '测试';
    const data = await app.mysql.query(sql, values); // 单实例可以直接通过 app.mysql 访问

  }

  

  async user() {
    const ctx = this.ctx;
    const { id } = ctx.query;
    const user = await ctx.service.user.find(id);
    user.user_tag = user.user_tag.split('%-%');
    ctx.body = {
      code: 1,
      data: user,
      msg: 'ok'
  };
  }
}

module.exports = HomeController;
